package com.lib.framework.utils

import android.content.Context
import android.content.pm.PackageManager
import androidx.core.content.ContextCompat


/**
 * 权限工具类
 *
 * @author keanbin
 */
class PermissionUtil {

    companion object {

        /**
         * 一组权限是否缺乏
         *
         * @return true 为缺乏，false 为拥有
         */
        @JvmStatic
        fun lacksPermission(context: Context, permissions: Array<String>): Boolean {
            for (permission in permissions) {
                if (lacksPermission(context,permission)) {
                    return true
                }
            }
            return false
        }

        /**
         * 判断是否缺少权限
         *
         * @return true 为缺乏，false 为拥有
         */
        @JvmStatic
        fun lacksPermission(context: Context, permission: String): Boolean {
            return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_DENIED
        }
    }
}